package com.huarui.companypackage.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.ewaf.framework.dao.impl.BaseDaoImpl;
import org.springframework.transaction.support.TransactionTemplate;

import com.huarui.companypackage.dao.ICompanyPackageDao;
import com.huarui.companypackage.model.CompanyService;
import com.huarui.companypackage.model.Package;
import com.huarui.companypackage.model.CompanyPackageService;
import com.huarui.companypackage.model.RoleEmployee;

public class CompanyPackageDaoImpl extends BaseDaoImpl implements ICompanyPackageDao  {


	private TransactionTemplate transactionTemplate;
	
	public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
		this.transactionTemplate = transactionTemplate;
	}
	
	public TransactionTemplate getTransactionTemplate() {
		return transactionTemplate;
	}


	@Override
	public CompanyService createCompanyService(CompanyPackageService packageService,
			Integer companyId) {
		
	     CompanyService companyService = new CompanyService();
		 companyService.setCompanyId(companyId);
		 companyService.setServiceCode(packageService.getServiceCode());
		 companyService.setServiceId(companyService.getServiceId());
		 companyService.setServiceName(packageService.getServiceName());
		 
		 this.getSqlMapClientTemplate().insert(namespace+".createCompanyService",companyId);
		 
		 return companyService;
	}

	@Override
	public List<CompanyService> createCompanyServices(List<CompanyPackageService> packageServices,Integer companyId){
		final List<CompanyService> companyServiceList = new ArrayList<CompanyService>();
		  for (CompanyPackageService packageService : packageServices) {
			  
			  CompanyService  companyService =createCompanyService(packageService, companyId); 
			  
			  companyServiceList.add(companyService);
		}
		
		 return companyServiceList; 
		  
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Package> getPackage(Integer companyType) {
		
		return this.getSqlMapClientTemplate().queryForList(namespace+".getPackageByCompanyType",companyType);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CompanyPackageService> getPackageService(Integer packageId) {
		
		return this.getSqlMapClientTemplate().queryForList(namespace+".getPackageServiceByPackageId",packageId);
	}

	@Override
	public void createRoleEmployee(RoleEmployee roleEmployee) {
	
		 this.getSqlMapClientTemplate().insert(namespace+"createRoleEmployee",roleEmployee);
	}
	
	
}
